import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            flow_plans: {
                offset: 0,
                length: 25,
                items: [{
                    title: '',
                }]
            },
        };
        return this.state;
    },
    allFlowPlan() {
        var me = this;
        var data = {};
        var flag = true;
        if(me.beforeAllFlowPlan) {
            flag = me.beforeAllFlowPlan(data);
        }
        if(flag) {
            app.get("api/flow_plans/all", data, function(res) {
                var data = [];
                for(var i = 0; i < res.data.result.data.length; i++) {
                    var m = {
                        title: res.data.result.data[i].title,
                    }
                    data.push(m);
                }
                me.setState({flow_plans: {items: data}});
                if(me.afterAllFlowPlan) {
                    me.afterAllFlowPlan(res);
                }
            });
        }
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {},
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
